<?php
class SumillasController extends AppController {

	var $name = 'Sumillas';
	var $components = array('RequestHandler');
	
	function index(){
		$this->layout="ajax";		
		if($this->JQGridPaginate->isGrid){
			$fields = array('Sumilla.id',			
			'Sumilla.tema',
			'Sumilla.detalle',
			'Sumilla.clase',
			'"Curso"."descripcion" AS "Sumilla__curso"',
			'Sumilla.created',
			'"Estado"."descripcion" AS "Sumilla__estado"');			
			$this->JQGridPaginate->recursive = 0;
			$this->JQGridPaginate->cakefields = $fields;
			echo $this->JQGridPaginate->paginate("Sumilla");
			$this->autoRender = false;
		}elseif($this->RequestHandler->isPost()){	
			$oper = $this->params['form']['oper'];
			if($oper == "add"){
				$this->Sumilla->create();				 
			}elseif ($oper == "edit"){
				$this->data['Sumilla']['id'] = $this->params['form']['id'];
			}elseif ($oper == "del"){
				$this->data['Sumilla']['id'] = $this->params['form']['id'];
				$this->data['Sumilla']['estado_id'] = 2;				
			}
			@$this->Sumilla->save($this->data['Sumilla']);
			echo json_encode($this->Sumilla->visualizarError($this->Sumilla->validationErrors));
			$this->autoRender = false;
		}		
	}
	
	function listaSumillas(){
		$this->layout="ajax";
		$listaSumillas = $this->Sumilla->find('list',array('fields'=>array('Sumilla.id','Sumilla.descripcion'),
															'order'=>'Sumilla.descripcion'));
		echo json_encode($listaSumillas);
		$this->autoRender = false;
	}
}